/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cip.esymons.sistemas.beans;

import java.util.List;
import javax.faces.model.SelectItem;
import org.cip.esymons.general.be.Area;
import org.cip.esymons.sistemas.bc.areaDelegate;

/**
 *
 * @author WILLIAM
 */

public class areaController {

    private areaDelegate delegadoArea;
    private Area area;

    public areaController() {

        delegadoArea = new areaDelegate();
        area = new Area();
    }

    public Area getArea() {
        return area;
    }

    public void setArea(Area area) {
        this.area = area;
    }

    public areaDelegate getDelegadoArea() {
        return delegadoArea;
    }

    public void setDelegadoArea(areaDelegate delegadoArea) {
        this.delegadoArea = delegadoArea;
    }

    public Area buscarArea(Integer codigo){

        return delegadoArea.find(codigo);
    }

    public SelectItem[] getSelectListaAreas(){

      try{
//        System.out.println("Ingreso 1");
        SelectItem[] selects = null;
        List<Area> listaArea = delegadoArea.findAll();
        selects = new SelectItem[listaArea.size()];
        int cont = 0;
        for(Area are : listaArea){

            SelectItem item = new SelectItem(are.getAreNombre(), are.getAreNombre());
            selects[cont] = item;
            cont++;
        }
        return selects;
      }catch(Exception e){
            System.out.println("Ingreso Error");
            SelectItem[] selects = new SelectItem[1];
            SelectItem item = new SelectItem(null, "No existen areas");
            selects[0] = item;
            return selects;
      }

    }

}
